﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MaterialSkin;
using MaterialSkin.Controls;
namespace taskbarApp
{
    public partial class Form1 : MaterialForm
    {
        public Form1()
        {
            InitializeComponent();
            var materialSkinManager = MaterialSkinManager.Instance;
            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = new ColorScheme(Primary.Green500, Primary.Green300, Primary.BlueGrey500, Accent.Green700, TextShade.WHITE);
        }

        /// <summary> /// 状态栏小图标的鼠标点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> 
        private void nIcon_Click(object sender, MouseEventArgs e)
        {
            try
            {
                if (this.WindowState == FormWindowState.Minimized)//当程序是最小化的状态时显示程序页面 
                {
                    this.WindowState = FormWindowState.Normal;
                }
                this.Activate();
                this.Visible = true; this.ShowInTaskbar = true;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        private void toolStripMenuItemExit_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("你确定要关闭吗！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (result == DialogResult.OK) 
            { 
                this.Dispose();
                this.Close();
                 Application.Exit();
            } 

           
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            try {
                e.Cancel = true; 
                this.Visible = false; 
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message); 
            }
        }
        /// <summary> /// 键盘按Esc，隐藏程序 /// </summary> ///
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
             if (e.KeyValue == 27) {    this.Hide(); }
        }

        private void materialFlatButtonRunMain_Click(object sender, EventArgs e)
        {
            //因为在 Form1_FormClosing 事件 进行了阻止， 所以close是最小化并隐藏的动作
            this.Close();
        }

        private void materialFlatButtonCloseApp_Click(object sender, EventArgs e)
        {
            //因为在 Form1_FormClosing 事件 进行了阻止， 所以close是最小化并隐藏的动作
            this.Close();
        }

        private void materialFlatButtonHide_Click(object sender, EventArgs e)
        {
            //因为在 Form1_FormClosing 事件 进行了阻止， 所以close是最小化并隐藏的动作
            this.Close();
        }

        private void materialFlatButton3_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("你确定要关闭吗！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (result == DialogResult.OK)
            {
                this.Dispose();
                this.Close();
                Application.Exit();
            } 
        }

    }
}
